package leetcode.biweekly.week101;

//Solution2Test
public class Solution2 {

	public int maximumCostSubstring(String s, String chars, int[] vals) {
		int cost[] = new int[26];
		for (int i = 0; i < 26; i++) {
			cost[i] = i + 1;
		}
		for (int i = 0; i < vals.length; i++) {
			cost[chars.charAt(i) - 'a'] = vals[i];
		}
		int ans = 0;
		int sum = 0;
		int min = 0;
		for (int i = 0; i < s.length(); i++) {
			sum += cost[s.charAt(i) - 'a'];
			ans = Math.max(ans, sum - min);
			min = Math.min(min, sum);
		}
		return ans;
	}

}
